package com.sugon.controller.device;

import com.sugon.annotation.AutoLog;
import com.sugon.entity.DevRecordOptionEntity;
import com.sugon.service.DevMainBaseService;
import com.sugon.service.DevRecordOptionService;
import com.sugon.utils.PageUtils;
import com.sugon.utils.Query;
import com.sugon.utils.R;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * 巡检记录选项关联Controller
 *
 * @author sugon
 * @date 2019-09-24 11:21:34
 */
@Controller
@RequestMapping("devrecordoption")
public class DevRecordOptionController {
    @Autowired
    private DevRecordOptionService devRecordOptionService;
    @Autowired
    private DevMainBaseService devMainBaseService;
    /**
     * 查看列表
     */
    @RequestMapping("/list")
    @ResponseBody
    public R list(@RequestParam Map<String, Object> params) {
        //查询列表数据
        Query query = new Query(params);

        List<DevRecordOptionEntity> devRecordOptionList = devRecordOptionService.queryList(query);
        int total = devRecordOptionService.queryTotal(query);

        PageUtils pageUtil = new PageUtils(devRecordOptionList, total, query.getLimit(), query.getPage());

        return R.ok().put("page", pageUtil);
    }

    /**
     * 查看信息
     */
    @RequestMapping("/info/{id}")
    @ResponseBody
    public R info(@PathVariable("id") String id) {
        DevRecordOptionEntity devRecordOption = devRecordOptionService.queryObject(id);

        return R.ok().put("devRecordOption", devRecordOption);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    @RequiresPermissions("devrecordoption:save")
    @ResponseBody
    public R save(@RequestBody DevRecordOptionEntity devRecordOption) {
        devRecordOptionService.save(devRecordOption);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    @RequiresPermissions("devrecordoption:update")
    @ResponseBody
    public R update(@RequestBody DevRecordOptionEntity devRecordOption) {
        devRecordOptionService.update(devRecordOption);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    @RequiresPermissions("devrecordoption:delete")
    @ResponseBody
    public R delete(@RequestBody String[] ids) {
        devRecordOptionService.deleteBatch(ids);

        return R.ok();
    }

    /**
     * 查看所有列表
     */
    @RequestMapping("/queryAll")
    @ResponseBody
    public R queryAll(@RequestParam Map<String, Object> params) {

        List<DevRecordOptionEntity> list = devRecordOptionService.queryList(params);

        return R.ok().put("list", list);
    }
    /**
     * 查看所有的维护库的信息
     */

    @RequestMapping("/saveMainBaseId/{planId}")
    @ResponseBody
    public R saveMainBaseId(@PathVariable("planId") String planId) {
        devMainBaseService.saveMainBaseId(planId);

        return R.ok();
    }

    @RequestMapping("/saveRecordOption")
    @ResponseBody
    public R saveRecordOption() {
        devRecordOptionService.saveRecordOption();

        return R.ok();
    }
    /**
     * 处理
     */
    @RequestMapping("/deal")
    @ResponseBody
    public R deal(@RequestBody DevRecordOptionEntity devRecordOption) {
        devRecordOptionService.deal(devRecordOption);
        return R.ok();
    }
}
